﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Web.Model;
using Portal.Web.Utility;
using Portal.Exam.Bussiness;
using Portal.Core;

namespace Portal.Exam.Render
{
    public class SelectExamRenderBll
    {
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                string UniCode = WebSessionUtility.GetCurrentLoginUser().AssetCode;
                string LoginName = WebSessionUtility.GetCurrentLoginUser().LoginName;
                DataTable dtExamList = new DoExamBll().ReadingStudentExamList(SiteId, UniCode, LoginName);
                string Html =
                    "<script language=javascript> \r\n" +
                    "    function DoSelect() {\r\n" +
                    "        SiteId='" + SiteId + "';\r\n" +
                    "        UniversityCode = document.getElementById('txtUniversityCode').value;\r\n" +
                    "        SelectName = document.getElementById('txtSelectName').value;\r\n" +
                    "        Password = document.getElementById('txtPassword').value;\r\n" +
                    "        AjaxOut = UNBP.University.SelectRenderBll.CheckForSelect(SiteId, UniversityCode, SelectName, Password).value;\r\n" +
                    "        if (AjaxOut.Error) {\r\n" +
                    "            alert(AjaxOut.InfoMessage);\r\n" +
                    "            return;\r\n" +
                    "        }\r\n" +
                    "        window.open(AjaxOut.RetUrl, '_self');\r\n" +
                    "    }\r\n" +
                    "</script>\r\n" +

                   "<div class=formSelectExam>\r\n" +
                   "    <div class=title>HỆ THỐNG THI TRẮC NGHIỆM ONLINE - CHỌN ĐỀ THI<input type=button class=button value=\"Quay lại\" onclick=\"javascript:window.open('login.aspx','_self');\" style=\"float:right;margin-right:2px;margin-top:-2px;\"></div>\r\n" +
                   "    <div class=body>\r\n" +
                   "        <div style=\"margin-top:2px;text-align:left;padding:8px;font-size:22px;\">\r\n" +
                   "            <div style=\"font-size:16px;margin-top:4px;padding:4px;color:Gray;font-style:italic\">Chào mừng bạn đã đến với hệ thống thi online. Xin vui lòng chọn bài thi để làm</div>\r\n" +
                   "        </div>\r\n" +
                   "        <div class=divInfo>\r\n";
                if (dtExamList.Rows.Count == 0)
                {
                    Html += "<div class=CssNoExam>Bạn không có đề thi nào trong danh sách</div>\r\n";
                }
                else
                {
                    Html +=
                        "   <div class=CssExamList>\r\n"+
                        "       <table>\r\n";
                    for (int iIndex = 0; iIndex < dtExamList.Rows.Count; iIndex++)
                    {
                        string ExamRoomStudentId = (string)dtExamList.Rows[iIndex]["ExamRoomStudentId"];
                        string ExamTitle = (string)dtExamList.Rows[iIndex]["ExamSubject"];
                        string ExamDescription = (string)dtExamList.Rows[iIndex]["ExamDescription"];
                        int UseTime = (int)dtExamList.Rows[iIndex]["UseTime"];
                        if (UseTime > 0)
                        {
                            ExamDescription += "<div class=CssHasExamMinutes>Đã làm được: " + UseTime + " phút</div>\r\n";
                        }
                        Html +=
                            "   <tr>\r\n" +
                            "       <td class=C1><a class=CssLinkExam href=\"DoExam.aspx?tid=" + ExamRoomStudentId + "\"><img class=CssExamImage src=\"Resources/Images/Exam.png\"></a></td>\r\n" +
                            "       <td class=C2><div class=CssExamTitle><a class=CssLinkExam href=\"DoExam.aspx?tid="+ExamRoomStudentId+"\">" + ExamTitle + "</a></div><div class=CssExamDescription>" + ExamDescription + "</div></td>\r\n" +
                            "   </tr>\r\n";
                    }
                    Html +=
                        "       </table>\r\n" +
                        "</div>\r\n";
                }

                Html +=
                    //"   <div class=divSelectHelp style=\"text-align:left;\">\r\n" +
                    //"       <ul>\r\n" +
                    //"           <li>Chú ý thời gian làm bài. Xin hướng dẫn trước khi bắt đầu làm bài</li>\r\n" +
                    //"       </ul>\r\n" +
                    //"   </div>\r\n" +
                    "   <div>\r\n" +
                   "        </div>\r\n" +
                   "    </div>\r\n" +
                   "</div>\r\n" +
                   "</td>\r\n" +
                   "</tr>\r\n" +
                   "</table>\r\n";
                if (!string.IsNullOrEmpty(UniCode))
                {
                    Html +=
                       "<script language=javascript>\r\n" +
                       "    document.getElementById('txtSelectName').focus();\r\n" +
                       "</script>\r\n";
                }

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

    }
}
